package chap4_2打印流;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author https://gitee.com/W_Jun
 * @date 2021-12-16 20:59
 * @Description 字符打印流
 */
public class PrintWriterDemo {
    public static void main(String[] args) throws IOException {
        //PrintWriter(String fileName)
        //PrintWriter pw = new PrintWriter("chapter04-特殊操作流\\src\\chap4_2打印流\\pw.txt");
/*        pw.write("hello");
        pw.write("\r\n");
        pw.flush();
        pw.write("world");
        pw.write("\r\n");
        pw.flush();
*//*
        pw.println("hello");
        pw.flush();
        pw.println("world");
        pw.flush();
*/
        //PrintWriter(Writer out,boolean autoFlush)
        PrintWriter pw = new PrintWriter(new FileWriter("chapter04-特殊操作流\\src\\chap4_2打印流\\pw.txt"), true);
        pw.println("hello");
        //因为构造方法中参数autoFlush为true，所以，println会自动刷新，不用再调用flush方法
        pw.println("world");
        pw.close();
    }
}
